const mongoose = require('mongoose');

// 一级评论是 答案的评论，二级评论是 评论的评论
const { Schema, model } = mongoose;
const commentSchema = new Schema({
  __v: { type: Number, select: false },
  content: { type: String, required: true },
  commentator: { type: Schema.Types.ObjectId, ref: 'User', required: true, select: false },
  questionId: { type: String, required: true },
  answerId: { type: String, required: true },
  // 一级评论没有这个属性 但是二级评论是有这个属性
  rootCommentId: { type: String },
  replyTo: { type: Schema.Types.ObjectId, ref: 'User' },
  createTime: {
    type: Date,
    select: false,
    default: Date.now
  },
  updateTime: {
    type: Date,
    select: false,
    default: Date.now
  }
}, { timestamps: { createdAt: 'createTime', updatedAt: 'updateTime' } });

module.exports = model('Comment', commentSchema);